/*
 * @Author: 丁平|1572804782@qq.com(dingping)
 * @Date: 2022-04-06 11:12:53
 * @LastEditors: 周润玉|zhourunyu1@outlook.com(zhourunyu)
 * @LastEditTime: 2022-07-13 14:39:56
 * @Participate: 参与修改人
 * @Description: 
 * @Administrator: 丁平|1572804782@qq.com(dingping)
 * @Copyright: 1.4.0.14
 */

import WorkReportMainApi from '../../../common/api/mybusiness/workreport/workreportmain.api.js'

/**
 * @file工作汇报main
 */
Utils.NameSpace('SN.H5.WorkReportMain');
(function (window, document, $) {
    'use strict';

    $(function () {
        _initEmploy();
        _initCommand()
    });

    const _initEmploy = async () => {
        let _employ = await WorkReportMainApi.getLoginUserToStaff();
        SN.H5.WorkReportMain.Employee = _employ;
        $('body').attr('data-weui-theme', 'light');
        // 使用location.replace来替换url避免切换锚点的操作被记录进history导致返回主页需要多次操作的问题
        $('.weui-tabbar__item').click(function () {
            location.replace($(this).attr('href'))
            $(this).addClass('weui-bar__item--on')
            $(this).siblings().removeClass('weui-bar__item--on')
            return false
        })
        $('#write-work-report').load(`../workreport/writereport/writereport.html?v=${Utils.GetTime()}`);
        $('#look-work-report').load(`../workreport/lookreport/lookreport.html?v=${Utils.GetTime()}`);
        tabBarClick('#work-report-auction');
        tabBarClick('#look-report-auction');
        let _state = Utils.GetRouterState('lookreport');
        if (Utils.IsNotNull(_state)) {
            let _json = JSON.parse(_state);
            return $(`#${_json.main}`).trigger("click");
        }
        $('#look-report-auction').trigger("click");
    }

    const tabBarClick = (id) => {
        $(id).on('click', function () {
            let tabId1 = $(this).attr('data-counterpart');
            let tabId = $(this).attr('href');
            $(tabId).show();
            $(tabId1).hide();
            location.hash = tabId;
            let _navbarId = $('#look-report-page-navbar .weui-bar__item--on').attr('href');
            setTimeout(() => {
                $(_navbarId).addClass('weui-tab__bd-item--active');
            })
        });

    }
    const _initCommand = () => {
        $('#work-report-auction').on('click', function () {
            $('#work-report-auction').css('display', 'none')
        })
    }

})(window, document, jQuery)